package com.example.loopyserver.component;

import org.springframework.stereotype.Component;

import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


@Component
public class TaskScheduler {

    private final ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(10,
            r -> new Thread(r, "Scheduled-Task-Thread"));

    public ScheduledFuture<?> addTask(Runnable task, int delayInSeconds) {
        return scheduler.schedule(task, delayInSeconds, TimeUnit.SECONDS);
    }
}
